<?php
include("includes/connect.php");
include("includes/function.php");


$tablename = $_POST["tablename"];
$dd = $_POST["dd"];
$fieldname = $_POST["fieldname"];
$idname = $_POST["idname"];
$by = $_POST["by"];

$ex3_id = $_POST["ex3_id"];


$db = new myDBS;

$where = "expenses2_id = $by";
$result = $db->showData1($tablename, $where);
?>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $dd; ?>").change(function() {
            var by = $(this).val();

            //alert(by);

        });
    });
</script>
<select class="span5" id="<?php echo $dd; ?>" name="<?php echo $dd; ?>" >
    <option value="">เลือก...</option>
    <?php
    while ($rows = $db->fetch_object($result)) {
        if ($rows->{$idname} == $ex3_id) {
            $selected = " selected";
        } else {
            $selected = "";
        }
        ?>
        <option value="<?php echo $rows->{$idname}; ?>" <?php echo $selected; ?>><?php echo $rows->{$fieldname}; ?></option>
    <?php } ?>
</select>